/*
 * Copyright 2013 Glassy Cinema.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package hu.glassy.web.component.common;

import hu.glassy.web.component.behaviour.DisableComponentOnAjaxCall;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.markup.html.form.Form;

/**
 * Ajax submit link kiterjesztett funkciókkal.
 *
 * @author molnar.alexander@sonrisa.hu
 */
public class CustomAjaxSubmitLink extends AjaxSubmitLink
{

  private static final long serialVersionUID = -1589563838363984782L;

  /**
   * Konstruktor
   *
   * @param id
   */
  public CustomAjaxSubmitLink(final String id)
  {
    this(id, null);
    setOutputMarkupId(true);
  }

  /**
   * Konstruktor
   *
   * @param id
   * @param form
   */
  public CustomAjaxSubmitLink(final String id, final Form<?> form)
  {
    super(id, form);
  }

  // --------------------------------------------------
  // ~ Overrided methods
  // --------------------------------------------------
  @Override
  protected void updateAjaxAttributes(final AjaxRequestAttributes attributes)
  {
    attributes.getAjaxCallListeners().add(new DisableComponentOnAjaxCall());
  }

  @Override
  protected void onSubmit(final AjaxRequestTarget target, final Form<?> form)
  {
    super.onSubmit(target, form);

    target.add(form);
  }

  @Override
  protected void onError(final AjaxRequestTarget target, final Form<?> form)
  {
    super.onError(target, form);

    target.add(form);
  }
}
